//
// Created by yyl on 2018/6/21.
//

#ifndef MYMUSIC_YVIDEO_H1
#define MYMUSIC_YVIDEO_H1

#include "yyl_log.h"
#include "YQueue.h"
#include "CallJava.h"
#include "yyl_ffmpeg.h"
#include "YAudio.h"

#define SoftwareAcceleration 1
#define HardwareAcceleration 2

class YVideo {


public :
    int streamIndex = -1;
    CallJava *callJava = NULL;
    AVCodecParameters *avCodecParameters = NULL;
    AVCodecContext *avCodecContext = NULL;
    PlayStatus *playStatus = NULL;
    YQueue *queue = NULL;
    AVRational time_base;
    pthread_t threadPlay;
    YAudio *audio = NULL;

    AVBSFContext *abs_ctx = NULL;

    int codecType = SoftwareAcceleration;
    int result = -1;
    double clock = 0;
    double delayTime = 0;
    double defaultDelayTime = 0;
    pthread_mutex_t codecMutexLock;
public :
    YVideo(PlayStatus *playStatus, CallJava *callJava);

    ~YVideo();

    void play();

    void release();

    void initVideoStart();

    double getFrameDiffTime(AVFrame *avFrame, AVPacket *avPacket);

    double getDelayTime(double diff);
};


#endif //MYMUSIC_YVIDEO_H1
